import datetime
from pydantic import BaseModel, Field, validator
from typing import List


class History(BaseModel):
    """日志查询 表字段查询"""
    page: int = Field(1, name='页码')
    count: int = Field(10, name='条数', description='每页最大展示条数')

    taskType: str = Field(..., name='开始时间')
    name: str = Field(None, name='名称')
    targetSearch: str = Field(None, name='资产名模糊搜索')
    status: str = Field(None, name='结束时间')
    securityStatus: List[str] = Field(None, name='状态')

    endTime_gte: datetime.datetime = Field(None, name='开始时间')
    endTime_lt: datetime.datetime = Field(None, name='结束时间')

    triggerType: str = Field(None, name='')
    vulTriggerType: str = Field(None, name='')

    sort: str = Field('-endTime', name='排序字段')

    @validator('securityStatus', pre=True)
    def validate_req_field(cls, field):
        return field.strip().split(',')
